<?php

namespace common\logics\address;

/**
 * FrontUserAddressLogic implements the CRUD actions for Brands model.
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class FrontUserAddressLogic extends \common\models\user\UserAddress {

    /**
     * 根据用户UID获取用户个人保存的收件地址
     * return array
     */
    public static function findByUserId($id) {
        return static::find()->where([
            'user_id' => $id
        ])
        ->orderBy([
            'is_default' => SORT_DESC,
            'created_at' => SORT_ASC,
        ])
        ->all();
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'name',
            'telephone' => 'mobile',
            'province',
            'city',
            'district',
            'address',
            'area_code' => 'area_code',
            'postal_code' => 'postal_code',
            'is_default' => 'isDefault',
            'tag'
        ];
    }

}
